package com.heatingcharge.controller.unit;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heatingcharge.common.util.R;
import com.heatingcharge.dto.HeatSourcePlantDTO;
import com.heatingcharge.entity.unit.HeatSourcePlant;
import com.heatingcharge.param.HeatSourcePlantParam;
import com.heatingcharge.service.unit.IHeatSourcePlantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 热源  前端控制器
 * </p>
 *
 * @author devin.jiang
 * @since 2019-07-12
 */
@RestController
@RequestMapping("/heat-source-plant")
public class HeatSourcePlantController {
    @Autowired
    IHeatSourcePlantService heatSourcePlantService;

    @ApiOperation(value = "分页获取热源厂",notes = "分页获取热源厂")
    @GetMapping
    public R getHeatSourcePlant(Page page,HeatSourcePlantDTO heatSourcePlantDTO){
        IPage<HeatSourcePlant> heatSourcePlantIPage = heatSourcePlantService.selectHeatSourcePlantPage(page,heatSourcePlantDTO);
        return R.ok(heatSourcePlantIPage);
    }

    @ApiOperation(value = "获取全部热源厂",notes = "获取全部热源厂")
    @GetMapping("/all")
    public R getAllHeatSourcePlant(HeatSourcePlantDTO heatSourcePlantDTO){
        List<HeatSourcePlant> heatSourcePlants = heatSourcePlantService.selectAllHeatSourcePlant(heatSourcePlantDTO);
        return R.ok(heatSourcePlants);
    }

    @ApiOperation(value = "新增热源厂",notes = "新增热源厂")
    @PostMapping
    public R saveHeatCompony(@RequestBody HeatSourcePlantParam heatSourcePlantParam){
        if (heatSourcePlantService.save(heatSourcePlantParam)){
            return R.ok();
        }
        return R.error();
    }

    @ApiOperation(value = "更新热源厂",notes = "更新热源厂")
    @PutMapping
    public R updateHeatCompony(@RequestBody HeatSourcePlantParam heatSourcePlantParam){
        if (heatSourcePlantService.update(heatSourcePlantParam)){
            return R.ok();
        }
        return R.error();
    }

    @ApiOperation(value = "删除热源厂",notes = "根据主键ID删除热源厂")
    @DeleteMapping("/{id}")
    public R delHeatCompony(@PathVariable("id") Integer id){
        if (heatSourcePlantService.removeById(id)){
            return R.ok();
        }
        return R.error();
    }
}

